<%-- 
    Document   : listManager
    Created on : Dec 19, 2014, 3:38:59 PM
    Author     : DucND
--%>
<%@page import="dao.ManagerDAO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="entity.Manager"%>
<jsp:include page="../header.jsp"></jsp:include>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    String username = (String) request.getSession().getAttribute("Username");
    //if (!ManagerDAO.isAdmin(username)) {
    //    response.sendRedirect("../public/index.jsp");
    //}
    List<Manager> managerList = new ArrayList<Manager>();
    managerList = ManagerDAO.getManagerList();
%>
<script>
    $(document).ready(function() {
        $('#example').dataTable();
    });
</script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>List of All Managers</title>
    </head>
    <body>
        <div class="container">
            <h2>Manager List</h2>
            <hr>
            <br>
            <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Username</th>
                        <td>Email</td>
                        <th>Role</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tr>
                    <%
                        int i = 1;
                        for (Manager ma : managerList) {
                    %>
                    <td><%=i++%></td>

                    <td><%=ma.getUsername()%></td>
                    <td><%=ma.getEmail()%></td>
                    <td><%if (ma.getRole()) {%>
                        <p>Admin</p>
                    <%} else {%>
                        <p>Manager</p>
                    <%}%></td>
                    <td>
                        <%if (!ManagerDAO.isAdmin(ma.getUsername()) && !username.equals(ma.getUsername())) {%>
                        <a href="./editManager.jsp?username=<%=ma.getUsername()%>">Edit </a> |
                        <a data-href="./deleteManager.jsp?username=<%=ma.getUsername()%>" data-toggle="modal" 
                           data-target="#confirm-delete"  href="#">Delete</a>
                        <%}%>
                    </td>
                </tr>
                <% }%>
            </table>
            <form action="addManager.jsp" method="POST" style="display: inline">
                <input type="submit" name="addNewBtn" class="btn btn-primary" value="Add new Manager" style="float: left" />
            </form>
        </div>

        <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">

                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Confirm</h4>
                    </div>

                    <div class="modal-body">
                        <p>Are you sure want to delete this Manager?</p>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                        <a href="#" class="btn btn-danger danger">Delete</a>
                    </div>
                </div>
            </div>
        </div>



        <script>
            $('#confirm-delete').on('show.bs.modal', function(e) {
                $(this).find('.danger').attr('href', $(e.relatedTarget).data('href'));
            })
        </script>
    </body>
</html>
<jsp:include page="../footer.jsp"></jsp:include>
